﻿@*
//------------------------------------------------------------------------------
//  此代码版权声明为全文件覆盖，如有原作者特别声明，会在下方手动补充
//  此代码版权（除特别声明外的代码）归作者本人Diego所有
//  源代码使用协议遵循本仓库的开源协议及附加协议
//  Gitee源代码仓库：https://gitee.com/diego2098/ThingsGateway
//  Github源代码仓库：https://github.com/kimdiego2098/ThingsGateway
//  使用文档：https://diego2098.gitee.io/thingsgateway-docs/
//  QQ群：605534569
//------------------------------------------------------------------------------
*@

@page "/admin/openapisession"
@using System.Linq.Expressions;
@using Masa.Blazor.Presets;
@using Microsoft.AspNetCore.Authorization;
@using ThingsGateway.Admin.Application;
 
@namespace ThingsGateway.Admin.Blazor
@attribute [Authorize]
@inject UserResoures UserResoures
@inherits BaseComponentBase
@layout MainLayout
<AppDataTable TItem="OpenApiSessionOutput" DescFunc=@(memberInfo=>memberInfo.GetCustomAttribute<SqlSugar.SugarColumn>(true)?.ColumnDescription)
              SearchItem="OpenApiSessionPageInput"
              AddItem="OpenApiSessionOutput" EditItem="OpenApiSessionOutput"
              SearchModel="@sessionSearch"
              QueryCallAsync="SessionQueryCallAsync"
              IsMenuOperTemplate=false
                IsShowQueryButton>

    <SearchTemplate>
        <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.Account"
                        Outlined Label=@context.Description(x => x.Account) />
        <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.LatestLoginIp"
                        Outlined Label=@context.Description(x => x.LatestLoginIp) />
    </SearchTemplate>

    <ItemColOperTemplate>
        <MButton Color="info" Text StopPropagation OnClick=@(()=>ShowVerificatListAsync(context.Item.VerificatSignList))>
            @context.Item.Description(it=>it.VerificatSignList)
        </MButton>
        @if (@UserResoures.IsHasButtonWithRole("openapisessionexit"))
        {
            <MButton Color="error" Text OnClick="()=>SessionExitAsync(context.Item.Id)">
                强退
            </MButton>
        }

    </ItemColOperTemplate>

    <HeaderTemplate>
        <MLabel class="text-subtitle">@context.Text</MLabel>
    </HeaderTemplate>

</AppDataTable>

<PDrawer @bind-Value="IsShowVerificatSignList" OnCancel="() => IsShowVerificatSignList = false"
         Title=@sessionOutput.Description(it => it.VerificatSignList)
         Width=@(IsMobile? "100%":1500)>
    @if (IsShowVerificatSignList)
    {
        <AppDataTable @ref="_verificatinfosDatatable" TItem="VerificatInfo" DescFunc=@(memberInfo=>memberInfo.GetCustomAttribute<SqlSugar.SugarColumn>(true)?.ColumnDescription)
                      SearchItem="BasePageInput" AddItem="object" EditItem="object"
                      QueryCallAsync="VerificatQueryCallAsync"
                      DeleteCallAsync="VerificatExitAsync" IsPage=true
                      IsMenuOperTemplate=false IsShowToolbar
                      IsShowDeleteButton=@UserResoures.IsHasButtonWithRole("openapiverificatdelete")>

            <ItemColTemplate>
                @switch (context.Header.Value)
                {
                    case nameof(context.Item.Device):
                        <MChip Class="ma-1">
                            @(context.Item.Device)
                        </MChip>
                        break;
                    default:
                        @if (context.Header.CellClass?.Contains("text-truncate") == true)
                        {
                            <span title=@context.Value>
                                @context.Value
                            </span>
                        }
                        else
                        {
                            @context.Value
                        }
                        break;
                }

            </ItemColTemplate>

        </AppDataTable>

    }
</PDrawer>

